#include "animation.h"

EAT_BUBBLE eat_bubble;
CHECKMATE_BUBBLE checkmate_bubble;
WIN_TEXTS win_texts;

int excursion[2][12];

extern int frame;


void excursion_init(){
    excursion[0][0] = -30;
    excursion[1][0] = -30;
    excursion[0][1] = 30;
    excursion[1][1] = 30;
    excursion[0][2] = -25;
    excursion[1][2] = -25;
    excursion[0][3] = 20;
    excursion[1][3] = 20;
    excursion[0][4] = -15;
    excursion[1][4] = -15;
    excursion[0][5] = 15;
    excursion[1][5] = 15;
    excursion[0][6] = -10;
    excursion[1][6] = -10;
    excursion[0][7] = 10;
    excursion[1][7] = 10;
    excursion[0][8] = -5;
    excursion[1][8] = -5;
    excursion[0][9] = 5;
    excursion[1][9] = 5;
    excursion[0][10] = 0;
    excursion[1][10] = 0;
    excursion[0][11] = 0;
    excursion[1][11] = 0;
}

void eat_bubble_init(){
    eat_bubble.playing = false;
    eat_bubble.crt_frame = 0;
    eat_bubble._sheet = al_load_bitmap("res/eat_bubble.png");
}

void checkmate_bubble_init(){
    checkmate_bubble.playing = false;
    checkmate_bubble.crt_frame = 0;
    checkmate_bubble._sheet = al_load_bitmap("res/checkmate_bubble.png");
}

void eat_bubble_update(){
    if(eat_bubble.playing){
        if(frame % 5 == 0)
            eat_bubble.crt_frame++;
        if(eat_bubble.crt_frame == 11){
            eat_bubble.crt_frame = 0;
            eat_bubble.playing = false;
        }
    }
}

void checkmate_bubble_update(){
    if(checkmate_bubble.playing){
        if(frame % 5 == 0)
            checkmate_bubble.crt_frame++;
        if(checkmate_bubble.crt_frame == 11){
            checkmate_bubble.crt_frame = 0;
            checkmate_bubble.playing = false;
        }
    }
}

void eat_bubble_draw(){
    if(eat_bubble.playing)
        al_draw_bitmap(eat_bubble._sheet, 600 + excursion[0][eat_bubble.crt_frame], 220 + excursion[1][eat_bubble.crt_frame], 0);
}

void checkmate_bubble_draw(){
    if(checkmate_bubble.playing)
        al_draw_bitmap(checkmate_bubble._sheet, 600 + excursion[0][checkmate_bubble.crt_frame], 220 + excursion[1][checkmate_bubble.crt_frame], 0);
}

void win_texts_init(){
    win_texts.win = false;
    win_texts.win_side = false;
    win_texts._sheet[1] = al_load_bitmap("res/press_anykey.png");
}

void win_texts_draw(){
    if(win_texts.win){
        win_texts._sheet[0] = al_load_bitmap(win_texts.win_side ? "res/win_red.png" : "res/win_black.png");
        al_draw_bitmap(win_texts._sheet[0], 380, 100, 0);
        al_draw_bitmap(win_texts._sheet[1], 830, 560, 0);
    }
}